﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UcToChuc.ascx.cs" Inherits="Viewer.NhanSu.UserControl.UcToChuc" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register Src="~/ToChuc/UserControl/UCDiaChi.ascx" TagName="UCDiaChi" TagPrefix="uc" %>
<ext:XScript ID="XScipt1" runat="server">
    <script type="text/javascript">
        var treePanelToChuc_Click = function(node) {
        #{DirectMethods}.SetTypeButton(node.id);
        }         
   </script>
</ext:XScript>
<link href="../../resources/css/main.css" rel="stylesheet" type="text/css" />
<ext:Window ID="wdToChuc" runat="server" Width="500" Height="500" Modal="true" Closable="false"
    StyleSpec="background-color:white;" Hidden="true" HideBorders="True" Border="false"
    Frame="false" Title="Tổ chức" AutoScroll="true" Icon="Find">
    <Items>
        <ext:CompositeField runat="server" ID="cpToChucKhac" Hidden="true">
            <Items>
                <ext:ComboBox ID="cbbTypeToChuc" runat="server" Width="150" SelectedIndex="0">
                    <Items>
                        <ext:ListItem Text="Thuộc sở y tê" Value="true" />
                        <ext:ListItem Text="Khác" Value="false" />
                    </Items>
                    <Listeners>
                    <Select Handler="if(#{cbbTypeToChuc}.getValue()=='true')
                                        {
                                            #{txtCoQuanKhac}.disable();
                                            #{treePanel}.enable();
                                        }
                                        else
                                        {
                                             #{txtCoQuanKhac}.enable();
                                             #{treePanel}.disable();
                                        }
                    "/>
                    </Listeners>
                </ext:ComboBox>
                <ext:TextField ID="txtCoQuanKhac" runat="server" Width="200" Disabled="true" EmptyText="Nhập tên tổ chức">
                </ext:TextField>
            </Items>
        </ext:CompositeField>
        <ext:CompositeField ID="CompositeField1" runat="server">
            <Items>
                <ext:treePanel ID="treePanel" runat="server" Icon="ChartOrganisation" Title="Tổ chức"
                    AutoScroll="true" Width="490" Collapsible="true">
                    <Listeners>
                        <Click Handler="treePanelToChuc_Click(node);" />
                    </Listeners>
                    <TopBar>
                        <ext:Toolbar ID="Toolbar1" runat="server">
                            <Items>
                                <ext:ToolbarTextItem ID="ToolbarTextItem1" runat="server" Text="Tìm kiếm:" />
                                <ext:ToolbarSpacer />
                                <ext:TriggerField ID="TriggerField1" runat="server" EnableKeyEvents="true">
                                    <Triggers>
                                        <ext:FieldTrigger Icon="Clear" />
                                    </Triggers>
                                    <Listeners>
                                        <KeyUp Fn="filterTree" Buffer="250" />
                                        <TriggerClick Handler="clearFilter();" />
                                    </Listeners>
                                </ext:TriggerField>
                            </Items>
                        </ext:Toolbar>
                    </TopBar>
                </ext:treePanel>
            </Items>
        </ext:CompositeField>
    </Items>
    <Buttons>
        <ext:Button ID="BtnSelectToChuc" runat="server" Text="Chọn tổ chức" Icon="Tick">
            <Listeners>
                <Click Handler="  
                var node=#{treePanel}.getSelectionModel().getSelectedNode();              
                if(node!=null && #{cbbTypeToChuc}.getValue()=='true')
                {
                      var nodeId=node.id;
                      var text=#{treePanel}.getSelectionModel().getSelectedNode().text;
                      InsertToChuc(nodeId,text);
                }
                else
                {
                      InsertToChuc(#{cbbTypeToChuc}.getValue(),#{txtCoQuanKhac}.getValue());
                }
                 #{wdToChuc}.hide();
              " />
            </Listeners>
        </ext:Button>
        <ext:Button ID="Button1" runat="server" Text="Đóng" Icon="Cancel">
            <Listeners>
                <Click Handler="#{wdToChuc}.hide();" />
            </Listeners>
        </ext:Button>
    </Buttons>
</ext:Window>
